<?php
defined('BASEPATH') OR exit('No direct script access allowed');
?>
<!--返回错误信息-->
<?php echo validation_errors(); ?>
<!DOCTYPE html>
<html lang="en">

<head>
    <?php
    $title = [
        'title' => '入库单编辑',
    ];
    $this->load->view('/admin/common/header', $title);
    ?>
</head>

<body data-type="widgets">
<script src="/assets/js/theme.js"></script>
<div class="am-g tpl-g">

    <!--    头部   侧边菜单-->
    <?php $this->load->view('/admin/common/bodyLeft'); ?>
    <script type="text/javascript">
        $(".js-sidebar-nav>li:nth-child(10)>ul").show(80);
        $(".js-sidebar-nav>li:nth-child(10)>a>span").addClass("sidebar-nav-sub-ico-rotate");
        $(".js-sidebar-nav>li:nth-child(10)>ul>li:nth-child(3)>a").addClass("active");
    </script>
    <!-- 内容区域 -->
    <div class="tpl-content-wrapper">
        <div class="row-content am-cf">
            <div class="row">
                <div class="am-u-sm-12 am-u-md-12 am-u-lg-12">
                    <div class="widget am-cf">
                        <div class="widget-head am-cf">
                            <div class="widget-title  am-cf">
                                <ol class="am-breadcrumb am-breadcrumb-slash">
                                    <li><a href="/admin/stock/put/index?page=1">库存管理</a></li>
                                    <li><a href="/admin/stock/put?page=1">商品入库</a></li>
                                    <li class="am-active">入库单编辑</li>
                                </ol>
                            </div>
                        </div>
                        <form  method="post" enctype="multipart/form-data" class="am-form am-text-sm" id="submitForm">
                            <div class="widget-body  am-fr">
                                <div class="tpl-table-black-operation">
                                    <a href="javascript:void(0);" class="tpl-table-black-operation-del">
                                        基本信息
                                    </a>
                                </div>

                                <div style="margin-top: 20px">
                                    <div class="am-g">
                                        <!-- Row start -->
                                        <div class="am-u-sm-12">
                                            <div class="am-g">
                                                <div class="am-u-md-6">
                                                    <div class="am-form-group am-u-sm-12">
                                                        <label class="am-u-md-2 am-md-text-right am-padding-left-0"
                                                               for="">单据编号</label>
                                                        <div class="am-u-md-10">
                                                            <input type="text" id="" name='stockPutCode' value="<?php echo $list['stockPutCode']?>" readonly>
                                                        </div>

                                                    </div>

                                                    <div class="am-form-group am-u-sm-12" >
                                                        <label class="am-u-md-2 am-md-text-right am-padding-left-0"
                                                               for="">收货方</label>
                                                        <div class="am-u-md-10">
                                                            <input type="text" id="" name='gonghuo' value="浙江爱思特科技发展有限公司" >
                                                        </div>


                                                    </div>


                                                    <div class="am-form-group am-u-sm-12">
                                                        <label class="am-u-md-2 am-md-text-right am-padding-left-0"
                                                               for="">制单人</label>
                                                        <div class="am-u-md-10">
                                                            <input type="text" id="" name='createMan' value="<?php echo $list['createMan']?>">
                                                        </div>
                                                    </div>

                                                    <div class="am-form-group am-u-sm-12">
                                                        <label class="am-u-md-2 am-md-text-right am-padding-left-0"
                                                               for="">申请原因</label>
                                                        <div class="am-u-md-10">
                                                            <textarea rows="5" id="" name="content"><?php echo $list['content']?></textarea>
                                                        </div>
                                                    </div>
                                                </div>

                                                <div class="am-u-md-6">
                                                    <div class="am-u-md-12">
                                                        <div class="am-form-group am-u-sm-12">
                                                            <label class="am-u-md-2 am-md-text-right am-padding-left-0 must"
                                                                   for="name">入库单名称：</label>
                                                            <div class="am-u-md-10">
                                                                <input  type="text"  name="name" value="<?php echo $list['name']?>"
                                                                        id="name">
                                                            </div>


                                                        </div>

                                                        <div class="am-form-group am-u-sm-12">
                                                            <label class="am-u-md-2 am-md-text-right am-padding-left-0"
                                                                   for="time">单据时间</label>
                                                            <div class="am-u-md-10">
                                                                <input type="text" class=" am-form-field" placeholder="单据时间" data-am-datepicker  name="time" id="time" value="<?php echo date('Y-m-d',$list['createTime'])?>" />
                                                            </div>
                                                        </div>

                                                        <div class="am-form-group am-u-md-12">
                                                            <label class="am-u-md-2 am-md-text-right am-padding-left-0"
                                                                   for="">供货方</label>
                                                            <div class="am-u-md-10">
                                                                <input type="text" id="" name='supplier' value="<?php echo $list['supplier']?>">
                                                            </div>
                                                        </div>

                                                        <div class="am-form-group am-u-sm-12">
                                                            <label class="am-u-md-2 am-md-text-right am-padding-left-0 must"
                                                                   for="source">所属项目</label>
                                                            <div class="am-u-md-10">

                                                                <?php
                                                                echo '<select class="form-control" name="source" id="source" data-am-selected="{btnWidth: \'100%\',maxHeight: 200}">

                                                                    ';
                                                                foreach ($project as $k=>$v){
                                                                    if($v['name'] == $list['source']){
                                                                        echo '<option value="'.$v['name'].'" selected>'.$v['name'].'</option>';

                                                                    }else{
                                                                        echo '<option value="'.$v['name'].'">'.$v['name'].'</option>';

                                                                    }
                                                                }
                                                                echo '</select>';
                                                                ?>
                                                            </div>


                                                        </div>


                                                    </div>
                                                </div>
                                            </div>
                                        </div>
                                        <!-- Row end -->
                                    </div>
                                    <hr>
                                </div>

                                <div class="tpl-table-black-operation">
                                    <a href="javascript:void(0);" class="tpl-table-black-operation-del">
                                        详细信息
                                    </a>
                                </div>

                                <div style="margin-top: 20px">
                                    <div class="am-u-sm-12">
                                        <table width="100%"
                                               class="am-table am-table-bordered am-table-radius am-table-striped"
                                               id="example-r">
                                            <thead>
                                                <tr>
                                                    <th style="width: 5%">序号</th>
                                                    <th style="width: 15%">商品编码</th>
                                                    <th style="width: 10%">商品名称</th>
                                                    <th style="width: 15%">商品规格</th>
                                                    <th style="width: 5%">单位</th>
                                                    <th style="width: 10%">入库数量</th>
                                                    <th style="width: 10%">入库单价(元)</th>
                                                    <th style="width: 10%">入库金额(元)</th>
                                                    <th style="width: 20%">备注</th>
                                                </tr>
                                            </thead>
                                            <tbody id="goodsMessage">
                                            <?php

                                            foreach ($list['goodsMessage'] as $k=>$v){
                                                echo '<tr class="line">
                                              
                                                   <td class="order">'.$v['order'].'</td>
                                                <td data-id="'.$v['dataId'].'" class="product_no">'.$v['product_no'].'</td>
                                                <td class="name">'.$v['name'].'</td>
                                                <td class="specification"  data-id="'.$v['stockPriceId'].'">'.$v['specification'].'</td>
                                                <td class="goodsUnit">'.$v['goodsUnit'].'</td>';

                                                if($list['status'] != 0 || strstr($v['specification'], '商品规格+')){
                                                    echo '<td>
                                                    <div class="am-form">
                                                        <input type="text" name="" class="am-u-md-12 form-control quantity" value="'.$v['quantity'].'" >
                                                    </div>
                                                </td>
                                                <td >
                                                    <div class="am-form">
                                                        <input type="text" name="" class="am-u-md-12 form-control price" value="'.$v['price'].'" >
                                                    </div>
                                                </td>
                                                <td class="price-all">'.$v['priceAll'].'</td>
                                                <td>
                                                    <div class="am-form">
                                                        <input type="text" name="" class="am-u-md-12 form-control remarks" value="'.$v['remarks'].'" >
                                                    </div>
                                                </td>
                                            </tr>';
                                                }else{
                                                    echo '          <td>
                                                    <div class="am-form">
                                                        <input type="text" name="" class="am-u-md-12 form-control quantity" value="'.$v['quantity'].'">
                                                    </div>
                                                </td>
                                                <td>
                                                    <div class="am-form">
                                                        <input type="text" name="" class="am-u-md-12 form-control price" value="'.$v['price'].'">
                                                    </div>
                                                </td>
                                                <td class="price-all">'.$v['priceAll'].'</td>

                                                <td>
                                                    <div class="am-form">
                                                        <input type="text" name="" class="am-u-md-12 form-control remarks" value="'.$v['remarks'].'">
                                                    </div>
                                                </td>
                                            </tr>';
                                                }

                                            }


                                            ?>
                                            </tbody>
                                        </table>
                                        <button type="button" class="am-btn am-btn-secondary"  data-am-modal="{target: '#changeCommodity', closeViaDimmer: 0, width: 900, height: 500}" id="chooseCommodity">选择商品</button>
                                        <div class="am-fr" style="font-size: 16px;line-height: 37px">
                                            共<span id="class"><?php $attribute = explode('/',$list['attribute']);echo $attribute[0].'</span>类,'.'<span id="quantity-all">'.$attribute[1].'</span>件商品';
                                                ?>

                                        </div>
                                        <hr>
                                    </div>
                                </div>

                                <div class="tpl-table-black-operation">
                                    <a href="javascript:void(0);" class="tpl-table-black-operation-del">
                                        审批信息
                                    </a>
                                </div>

                                <div style="margin-top: 20px">
                                    <div class="am-g">
                                        <!-- Row start -->
                                        <div class="am-u-sm-4">
                                            <div class="am-form-group am-u-sm-12">
                                                <label class="am-u-md-4 must">选择审批人:</label>
                                                <label class="am-u-md-4 am-md-text-right am-padding-left-0" for="director">一级审批人</label>
                                                <div class="am-u-md-4">
                                                    <?php
                                                    if($list['status'] != 2){
                                                        echo '<select data-am-selected="{btnSize: \'sm\'}" name="director" id="director" disabled>
                                                            <option value="">请选择一级审批人</option>
                                                        </select>';
                                                    }else{
                                                        echo '<select data-am-selected="{btnSize: \'sm\'}" name="director" id="director">
                                                            <option value="">请选择一级审批人</option>
                                                        </select>';
                                                    }
                                                    ?>
                                                </div>
                                                    
                                            </div>
                                            <div class="am-form-group am-u-sm-12">
                                                <label class="am-u-md-4 "></label>
                                                <label class="am-u-md-4 am-md-text-right am-padding-left-0"
                                                           for="president">二级审批人</label>
                                                <div class="am-u-md-4">
                                                    <?php
                                                    if($list['status']!= 2){
                                                        echo '<select data-am-selected="{btnSize: \'sm\'}" name="president" id="president" disabled>
                                                            <option value="">请选择二级审批人</option>
                                                        </select>';
                                                    }else{
                                                        echo '<select data-am-selected="{btnSize: \'sm\'}" name="president" id="president">
                                                            <option value="">请选择二级审批人</option>
                                                        </select>';
                                                    }
                                                    ?>
                                                </div>
                                                <input type="hidden" name="id" value="<?php echo $list['id'] ?>">
                                            </div>

                                            <input type="hidden" name="isAdd" value="1">



<!--                                           <div class="am-form-group am-u-sm-12">-->
<!--                                                <label class="am-u-md-4"></label>-->
<!--                                                <label class="am-u-md-4 am-md-text-right am-padding-left-0"-->
<!--                                                           for="financial">审批抄送人</label>-->
<!--                                                <div class="am-u-md-4">-->
<!--                                                    <select data-am-selected="{btnSize: 'sm'}" name="financial" id="financial">-->
<!--                                                        <option value=""></option>-->
<!---->
<!--                                                    </select>-->
<!--                                                </div>-->
<!--                                            </div>-->
                                        </div>
                                    </div>
                                </div>
                                <!-- Row end -->
                            </div>
                            <div class="btn-box">
                                <?php
                                if($list['status'] != 2){
                                    echo '<button onclick="back()" type="button" class="am-btn am-btn-primary tpl-btn-bg-color-success" style="width:220px;margin: 20px;">取消</button>';
                                }else{
                                    echo '
                                <input type="submit" value="提交" class="am-btn am-btn-primary tpl-btn-bg-color-success commit" style="width:220px;margin: 20px;">
                                <button onclick="back()" type="button" class="am-btn am-btn-primary tpl-btn-bg-color-success" style="width:220px">取消</button>
                                ';
                                }
                                ?>
                            </div>
                        </form>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
<!-- 模态框 -->
<div class="am-modal am-modal-no-btn" tabindex="-1" id="addSpecification">
    <div class="am-modal-dialog">
        <div class="am-modal-hd">选择规格
            <a href="javascript: void(0)" class="am-close am-close-spin" data-am-modal-close>&times;</a>
        </div>
        <div class="am-modal-bd">
            <table class="am-table am-table-bordered am-table-radius am-table-striped am-table-hover">
                <thead>
                    <tr>
                        <th style="width: 60%">规格</th>
                        <th style="width: 40%">进货数量</th>
                    </tr>
                </thead>
                <tbody class="specification-box">
                    <!-- <tr>
                        <td class="specification-value">白色</td>
                        <td class="specification-value">XL</td>
                        <td class="specification-value">塑料</td>
                        <td><div class="am-form"><input type="text" name="" class=""></div></td>
                    </tr>
                    -->
                </tbody>
            </table>
        </div>
        <div class="btn-box">
            <button type="searchCommoditybutton" class="am-btn am-btn-primary" id="confirmSpecification" data-am-modal-close>确认</button>
        </div>
    </div>
</div>
<!-- 模态框 -->
<div class="am-modal am-modal-no-btn" tabindex="-1" id="changeCommodity">
  <div class="am-modal-dialog">
    <div class="am-modal-hd">选择商品
      <a href="javascript: void(0)" class="am-close am-close-spin" data-am-modal-close>&times;</a>
    </div>
    <div class="am-modal-bd">
        <div class="fl">
            <div class="list-title">
                所有分类
            </div>
            <div class="left-list">

            </div>
        </div>
        <div class="fr goods-details">
            <form class="am-form am-form-horizontal">
                <div class="am-form-group search-box">
                    <div class="am-u-sm-8 search-input">
                        <input type="text" id="searchValue" placeholder="请输入商品名称查询。">
                    </div>
                    <div class="am-u-sm-2" >
                        <button type="button" class="am-btn am-btn-success" id="searchCommodity">查询</button>
                    </div>
                    <div class="am-u-sm-2">
                        <button type="button" class="am-btn am-btn-primary" id="addCommodity" data-am-modal-close>确认</button>
                    </div>
                </div>
            </form>
            <div class="am-u-sm-12 table-box">
                <table class="am-table am-table-bordered am-table-radius am-table-striped am-table-hover">
                    <thead>
                        <tr>
                            <th style="width: 5%;"><input type="checkbox" class="check-all" name=""></th>
                            <th style="width: 10%;">序号</th>
                            <th style="width: 25%;">商品编号</th>
                            <th style="width: 25%;">商品名称</th>
                            <th style="width: 10%;">单位</th>
                            <th style="width: 15%;">缺货数量</th>
                        </tr>
                    </thead>
                    <tbody class="tr-box">

                    </tbody>
                </table>
            </div>

            <div class="pagination-box">
                <ul class="am-pagination" id="pagination">
                  <!-- <li class="am-disabled"><a href="#">&laquo;</a></li>
                  <li class="am-active"><a href="#">1</a></li>
                  <li><a href="#">2</a></li>
                  <li><a href="#">3</a></li>
                  <li><a href="#">4</a></li>
                  <li><a href="#">5</a></li>
                  <li><a href="#">&raquo;</a></li> -->
                </ul>
            </div>
        </div>
    </div>
</div>

<script src="/assets/js/amazeui.min.js"></script>
<script src="/assets/js/amazeui.datatables.min.js"></script>
<script src="/assets/js/dataTables.responsive.min.js"></script>
<script src="/assets/js/app.js"></script>
<script src="/assets/js/zdy_form.js"></script>
<script src="/assets/js/page.js"></script>
<script src="/assets/js/procurement.js"></script>
    <script>


        $(function(){
            var thisId = GetQueryString("id");
            addAudit(thisId,"/admin/user/editOneLevel","#director");//添加一级审批人
            addAudit(thisId,"/admin/user/editTwoLevel","#president");//添加二级审批人
//            addAudit(thisId,"/admin/user/editCCLevel","#financial");//添加审批抄送人

            calcPriceAndNum();
            requestSpecification();

            //点击选择商品
            $("#chooseCommodity").click(function(){
                initCategory();
                levelClick(0,0,1);
            });
            //点击分类
            var unlock = true;
            $(document).on("click",".level1",function(){
                if (unlock == false) {
                    return;
                }
                unlock = false;
                $("#searchValue").val("");
                var sib1 = $(this).siblings(".level2-box");
                var category = $(this).children().data("category");
                sib1.slideToggle(function(){
                    unlock = true;
                });
                if(!$(this).children().find(".am-icon-angle-right").hasClass("transform90")){
                    $(this).children().find(".am-icon-angle-right").addClass("transform90");
                }else{
                    $(this).children().find(".am-icon-angle-right").removeClass("transform90");
                }
                levelClick(category,1,1);
            });

            $(document).on("click",".level2",function(){
                if (unlock == false) {
                    return;
                }
                unlock = false;
                $("#searchValue").val("");
                var sib2 = $(this).siblings(".level3-box");
                var category = $(this).children().data("id");
                sib2.slideToggle(function(){
                    unlock = true;
                });
                if(!$(this).children().find(".am-icon-angle-right").hasClass("transform90")){
                    $(this).children().find(".am-icon-angle-right").addClass("transform90");
                }else{
                    $(this).children().find(".am-icon-angle-right").removeClass("transform90");
                }
                levelClick(category,2,1);
            });
            $(document).on("click",".level3",function(){
                $("#searchValue").val("");
                var category = $(this).children().data("id");
                levelClick(category,3,1);
            });

            //点击查询 商品按钮
            $("#searchCommodity").on("click",function(){
                var search = $("#searchValue").val();
                if(!search){
                    alert("请输入商品名称查询。");
                    return false;
                }
                levelClick(0,0,1,search);
            });


            //点击确认
            var max = 0;
            var lineorder = $("#goodsMessage").find(".order");
            var maxorder = 0;
            for(var i = 0;i < lineorder.length; i++){
                maxorder = lineorder.eq(i).html() == "" ? 0 : parseInt(lineorder.eq(i).html());
                max = Math.max(max,maxorder);
            }

            $("#addCommodity").click(function(){
                var whichCheck = $(".check-one:checked");
                var tr='';
                for(var i = 0;i < whichCheck.length; i++){
                    var priceAll = '';
                    var product_no = whichCheck.eq(i).parent().siblings(".product_no").text();
                    var name = whichCheck.eq(i).parent().siblings(".name").text();
                    var goodsUnit = whichCheck.eq(i).parent().siblings(".goodsUnit").text();
                    var dataId = whichCheck.eq(i).data("id");
                    var ckId = whichCheck.eq(i).data("ckid");
                    var stockpriceid = whichCheck.eq(i).data("stockpriceid");
                    var classNum;    //类数量
                    var hasSpecification = whichCheck.eq(i).data("has");  //是否有规格  1：有  0：无
                    max++;
                    classNum = max;
                    if(max < 10){
                        max = "0" + max;
                    }
                    tr += '<tr class="line"><td class="order">'+ max +'</td>'
                        +'<td data-id="'+ dataId +'" data-ckid="'+ ckId +'" class="product_no">'+ product_no +'</td>'
                        +'<td class="name">'+ name +'</td>';
                    if(hasSpecification == 1){
                        tr += '<td class="specification"><button type="button" class="am-btn am-btn-default am-radius specification-btn" data-am-modal="{target: \'#addSpecification\', closeViaDimmer: 0, width: 500, height: 400}">商品规格+</button></td>'
                            + '<td class="goodsUnit">'+ goodsUnit +'</td>'
                            +'<td><div class="am-form"><input type="text" name="" class="am-u-md-12 form-control quantity" readonly="readonly"></div></td>'
                            +'<td><div class="am-form"><input type="text" name="" class="am-u-md-12 form-control price" readonly="readonly"></div></td>'
                            +'<td class="price-all">'+ priceAll +'</td>'
                            +'<td><div class="am-form"><input type="text" name="" class="am-u-md-12 form-control remarks"></div></td></tr>';
                    }else{
                        tr += '<td class="specification" data-id="'+ stockpriceid +'"></td>'
                            + '<td class="goodsUnit">'+ goodsUnit +'</td>'
                            +'<td><div class="am-form"><input type="text" name="" class="am-u-md-12 form-control quantity"></div></td>'
                            +'<td><div class="am-form"><input type="text" name="" class="am-u-md-12 form-control price"></div></td>'
                            +'<td class="price-all">'+ priceAll +'</td>'
                            +'<td><div class="am-form"><input type="text" name="" class="am-u-md-12 form-control remarks"></div></td></tr>';
                    }

                }
                $("#goodsMessage").append(tr);
                $("#class").text(classNum);  //多少类商品


                //请求规格
                requestSpecification();

                calcPriceAndNum();
            });

            if(<?php echo $list['status'] ?> != 2){

                $(".specification-btn").attr("disabled","disabled");
                $("#chooseCommodity").attr("disabled","disabled");
                $("input").attr("readonly","readonly");
                $("textarea").attr("readonly","readonly");
                $("#endTime").attr("disabled","disabled");
                $("#createTime").attr("disabled","disabled");

            }

            var lockSubmit = false;

            $(".commit").bind("click",function(e){
                e.preventDefault();
                if(lockSubmit){
                    return false;
                }
                lockSubmit =true;
                // 表单验证
//                var valid = zdy.validate.valid({
//                    rules:{
//                        name:{required:true},
//                        source:{required:true},
//                        contactMan:{required:true},
//                        createTime:{required:true},
//                        content:{required:true},
//                        director:{required:true},
//                        president:{required:true},
//                        financial:{required:true},
//                    }, message:{
//                        name:{required:"请填写需求单名称"},
//                        source:{required:"请填写所属项目"},
//                        contactMan:{required:"请填写发起人"},
//                        createTime:{required:"请选择发起时间"},
//                        content:{required:"请输入申请原因"},
//                        director:{required:"请选择一级审批人"},
//                        president:{required:"请选择二级审批人"},
//                        financial:{required:"请选择审批抄送人"},
//                    }
//                });
//                if (!valid) {
//                    lockSubmit = false;
//                    return;
//                }

                var formData = new FormData($("#submitForm")[0]);
                var action = $(this).val();
                var attribute = $("#class").text() + "/" + $("#quantity-all").text();
                var goodsMessage = getGoodsMessage();

                if(goodsMessage.length <= 2){
                    $("#pop-up-content").text("请选择商品");
                    $("#my-alert").modal();
                    lockSubmit = false;
                    return;
                }

                formData.append("attribute",attribute);
                formData.append("action",action);
                formData.append("amount",getAllPrice());
                formData.append("goodsMessage",goodsMessage);
                $.ajax({
                    type: "POST",
                    url : '/admin/stock/putEdit',
                    data: formData,
                    cache: false,
                    processData: false,
                    contentType: false,
                    success: function(data){
                        window.location.href = '/admin/stock/put?page=1';
                    },
                    error: function(XMLHttpRequest, textStatus, errorThrown) {
                        alert(XMLHttpRequest.status);
                        alert(XMLHttpRequest.readyState);
                        alert(textStatus);
                    },
                });
                return false;
            });



            //全选反选
            $("#changeCommodity .check-all").click(function(){
                $("#changeCommodity .check-one").prop("checked",this.checked);
            });

        });
        function requestSpecification() {
            $(".specification-btn").unbind("click").click(function(){
                var thisTr = $(this).parents(".line");                   //点击的本行tr
                var productId = thisTr.find(".product_no").data("id");   //传给后台的商品ID
                var ckId = thisTr.find(".product_no").data("ckid");   //传给后台的商品ID
                var product_no = thisTr.find(".product_no").text();   //商品编码
                var name = thisTr.find(".name").text();               //名字
                var goodsUnit = thisTr.find(".goodsUnit").text();     //单位
                var specificationData;                                  //请求规格传给后台的ID
                specificationData = ckId ? ckId : productId;
                $.ajax({
                    url:"/api/goods/getGoodsByStock",
                    data:{
                        productId:specificationData
                    },
                    dataType:"json",
                    type:"post",
                    async:false,
                    success:function(data){
                        var specificationBox = $(".specification-box");
                        var tr='';
                        for(var i = 0; i < data.length; i++){
                            var specificationId = data[i].id;
                            var specificationArray = data[i].stock.join();
                            tr += '<tr data-id="'+ specificationId +'">'
                                + '<td class="specification-value">'+ specificationArray +'</td>'
                                + '<td>'
                                + '<div class="am-form">'
                                + '<input type="text" name="" class="">'
                                + '</div>'
                                + '</td>'
                                + '</tr>';
                        }
                        specificationBox.html(tr);
                    },
                    error:function(data){
                        console.log(data);
                    }
                });

                // 点击确定添加新规格商品
                $("#confirmSpecification").unbind("click").click(function(){
                    var stockInput = $(".specification-box").find("input");
                    var specificationTr = '';
                    var oneGoodsNum = 0;

                    for(var i = 0;i < stockInput.length; i++){
                        if(stockInput.eq(i).val() == 0 || stockInput.eq(i).val().replace(/(^\s*)|(\s*$)/g, "")==""){
                            continue;
                        }
                        var stockInputVal = stockInput.eq(i).val();  //进货数量
                        var specificationVal = stockInput.eq(i).parents("tr").find(".specification-value").text(); //规格
                        var stockPriceId = stockInput.eq(i).parents("tr").data("id");
                        specificationTr += '<tr class="line">'
                            + '<td class="orde  r"></td><td class="product_no" data-id="'+ productId +'">'+ product_no +'</td>'
                            + '<td class="name">'+ name +'</td>'
                            + '<td class="specification" data-id="'+ stockPriceId +'">'+ specificationVal +'</td>'
                            + '<td class="goodsUnit">'+ goodsUnit +'</td>'
                            + '<td><div class="am-form"><input type="text" name="" value="'+ stockInputVal +'" class="am-u-md-12 form-control quantity"></div></td>'
                            + '<td><div class="am-form"><input type="text" name="" class="am-u-md-12 form-control price"></div></td>'
                            + '<td class="price-all"></td>'
                            + '<td><div class="am-form"><input type="text" name="" class="am-u-md-12 form-control remarks"></div></td></tr>';

                    }

                    thisTr.after(specificationTr);

                    for(var k = 0 ; k < $("#goodsMessage").find(".quantity").length; k++){
                        var quantityInp = $("#goodsMessage").find(".quantity").eq(k).val();
                        quantityInp = quantityInp == "" ? 0 : quantityInp;
                        oneGoodsNum += parseInt(quantityInp);
                    }
                    $("#quantity-all").text(oneGoodsNum);

                    calcPriceAndNum();
                });

            });
        }

        // 添加审批人员
        function addAudit(id,url,selectId){
            $.ajax({
                url:url,
                data:{
                    id: id,
                    type:"<?php echo $list['type'] ?>"
                },
                dataType:"json",
                type:"post",
                success:function(data){
                    console.log(data)
                    var nickname;
                    var selectBoxId = $(selectId);
                    var opation ="";
                    for(var key in data){
                        if(key == "presentValue"){
                            break;
                        }
                        nickname = data[key].nickname;
                        if(nickname == data.presentValue){
                            opation += '<option value="'+ nickname +'" selected="selected">'+ nickname +'</option>';
                        }else{
                            opation += '<option value="'+ nickname +'">'+ nickname +'</option>';
                        }
                    }
                    selectBoxId.append(opation);
                }
            });
        }

    </script>
</body>

</html>